home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / SORT_UTL / SORTIN / SORTDEMO.PAS < prev    next >
Pascal/Delphi Source File  |  1988-12-25  |  2KB  |  79 lines

  1. program SortDemo;
  2.    uses Sorting,TypeSpec,DistSort,Crt;
  3. {=============================================}
  4. {            James L. Allison                 }
  5. {            1703 Neptune Lane                }
  6. {            Houston, Texas  77062            }
  7. {            Dec 22, 1988                     }
  8. {=============================================}
  9.  
  10. { Please feel free to use any part of this in any of your programs.}
  11.  
  12. var
  13.    I:integer;
  14.    Jump:integer;
  15.  
  16. (*---------------------------------------------------------------------*)
  17. function Rnd(Xlo,Xhi:integer):integer;
  18.    {random from xlo to xhi INCLUSIVE}
  19.    begin
  20.       Rnd:=Random(1+Xhi-Xlo)+Xlo;
  21.    end;
  22. (*---------------------------------------------------------------------*)
  23. function Prompt:integer;
  24. var
  25.    Temp:Char;
  26.    begin
  27.       repeat
  28.          ClrScr;
  29.          WriteLn('When the random array has been loaded,');
  30.          WriteLn('press any key to start the sort.');
  31.          WriteLn('(After the sort, press any key to continue.)');
  32.          WriteLn('');
  33.          WriteLn('1 -- LoopSort');
  34.          WriteLn('2 -- BubbleSort');
  35.          WriteLn('3 -- ShellSort');
  36.          WriteLn('4 -- QuickSort');
  37.          WriteLn('5 -- DistributionSort');
  38.          WriteLn('6 -- EXIT');
  39.          WriteLn('');
  40.          Write('Select>');
  41.          Temp:=ReadKey;
  42.       until(Temp>='1') and (Temp<='6');
  43.       Prompt:=ord(Temp)-ord('1')+1;
  44.    end;
  45.  
  46. var
  47.    P:^List;
  48.    Q:^Screen_Buffer;
  49.    Key:char;
  50. const
  51.    N=2000;
  52.    begin
  53.       if Lastmode=Mono     {set video memory}
  54.          then P:=ptr($B000,$0000)
  55.          else P:=ptr($B800,$0000);
  56.       Q:=Pointer(P);
  57.       repeat
  58.          Jump:=Prompt;
  59.          ClrScr;
  60.          if Jump=6 then HALT;
  61.          RandSeed:=12345;  {so all tests are against the same data}
  62.          for I:=0 to N-1 do Q^[I][Value]:=Rnd(ord('A'),ord('z'));
  63.          Key:=ReadKey;
  64.          case Jump of
  65.             1:LoopSort         (P^,Less,N);
  66.             2:BubbleSort       (P^,Less,N);
  67.             3:ShellSort        (P^,Less,N);
  68.             4:QuickSort        (P^,Less,N);
  69.             5:DistributionSort (P^,N);
  70.             6:begin
  71.                 ClrScr;
  72.                 HALT;
  73.               end;
  74.          end {case};
  75.          Key:=ReadKey;
  76.       until false;
  77.    end.
  78.  
  79.